package com.csun.watch.watchmain;

import android.content.Context;

import com.csun.nusing.bean.UrlBean;
import com.csun.nusing.util.SPUtils;
import com.google.gson.Gson;
import com.home.administrator.okhttplibrary.IOkTaskCallback;
import com.home.administrator.okhttplibrary.OkHttpTask;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者: Created by fzq on 2018/7/30 10:48
 * 邮箱: 15997123593@163.com
 */
public class WatchMainModelImpl implements WatchMainModel {

    @Override
    public void getDeviceInfo(final MainCallBack mainCallBack, Context context, String deviceId) {

        String authorization = (String) SPUtils.get(context, "authorization", "");
        Map<String, String> param = new HashMap<String, String>();
        param.put("id", deviceId);
        OkHttpTask.newInstance(context).post(param, OkHttpTask.OkHttpTaskBuidler.OkType.form)
                .addHeader("authorization", authorization)
                .enqueue(new IOkTaskCallback() {
                    @Override
                    public void onSuccess(String result) {
                        if (result != null) {
                            Gson gson = new Gson();
                            DeviceInfoJsonBean bean = gson.fromJson(result,
                                    DeviceInfoJsonBean.class);
                            mainCallBack.callData(bean);
                        }
                    }
                }).start(UrlBean.NURSINGBYOLDMANURL);
    }

    @Override
    public void getOlderInfo(MainCallBack mainCallBack, Context context, String olderId) {
//        mainCallBack.callOlderData();
    }
}
